package cn.com.netedge.iot.frontend.datasave.model.freeze;

import java.util.ArrayList;
import java.util.List;

public class FreezeDataModel {
    private int meterId;
    private String tableName;
    /** 动态列值以及类型 */
    private List<ColumnDataModel> columnDataModels;

    private String dynamicsColumns;
    private String dynamicsValues;

    public String getDynamicsValues() {
        if (columnDataModels.isEmpty()) {
            return "";
        }

        StringBuilder stringBuilder = new StringBuilder();
        for (ColumnDataModel col : columnDataModels) {
            if ("numeric".equals(col.getDataType())) {
                stringBuilder.append(",");
                stringBuilder.append((col.getDataValue().contains(",") ? col.getDataValue().replace(',', '.') : col.getDataValue()));
            } else {
                stringBuilder.append(",'").append(col.getDataValue()).append("'");
            }
        }
        dynamicsValues = stringBuilder.toString();
        return dynamicsValues;
    }


    public String getDynamicsColumns() {
        if (columnDataModels.isEmpty()) {
            return "";
        }

        StringBuilder stringBuilder = new StringBuilder();
        for (ColumnDataModel col : columnDataModels) {
            stringBuilder.append(",").append(col.getColumnName());
        }
        this.dynamicsColumns = stringBuilder.toString();
        return dynamicsColumns;
    }


    public FreezeDataModel() {
        this.columnDataModels = new ArrayList<>();
    }

    public int getMeterId() {
        return meterId;
    }

    public void setMeterId(int meterId) {
        this.meterId = meterId;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public List<ColumnDataModel> getColumnDataModels() {
        return columnDataModels;
    }

    public void setColumnDataModels(List<ColumnDataModel> columnDataModels) {
        this.columnDataModels = columnDataModels;
    }
}
